﻿using System;
namespace Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="KLVaartus", Namespace="http://producers.etoimik.xtee.riik.ee/producer/etoimik", Target=typeof(KLVaartus))]
    public class KLVaartusSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IKLVaartus clazz;
        
        public KLVaartusSerializer(IKLVaartus clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            if (clazz.Vaartus!=null) {
                Writer.WriteStartElement("Vaartus");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Vaartus))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.LyhiVaartus!=null) {
                Writer.WriteStartElement("LyhiVaartus");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.LyhiVaartus))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Kirjeldus!=null) {
                Writer.WriteStartElement("Kirjeldus");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Kirjeldus))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.AlgusKP!=null) {
                Writer.WriteStartElement("AlgusKP");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "dateTime");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDateTime(((System.DateTime)(clazz.AlgusKP))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.LoppKP!=null) {
                Writer.WriteStartElement("LoppKP");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "dateTime");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDateTime(((System.DateTime)(clazz.LoppKP))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.ObjektID!=null) {
                Writer.WriteStartElement("ObjektID");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "long");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdLong(((long)(clazz.ObjektID))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.SeaduseSatted!=null) {
                Writer.WriteStartElement("SeaduseSatted");
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute("SeaduseSate", "http://producers.etoimik.xtee.riik.ee/producer/etoimik", clazz.SeaduseSatted.Count);
                for (int x = 0; ((clazz.SeaduseSatted != null) 
                            && (x < clazz.SeaduseSatted.Count)); x = (x + 1)) {
                    if (clazz.SeaduseSatted[x]!=null) {
                        Writer.WriteStartElement("item");
                        global::Xtee.Core.SerializationMetadata metaSeaduseSatted = this.GetMetaData(clazz.SeaduseSatted[x]);
                        Writer.WriteTypeAttribute(metaSeaduseSatted.TypeQualifiedName.Namespace, metaSeaduseSatted.TypeQualifiedName.Name);
                        metaSeaduseSatted.NewSerializer(clazz.SeaduseSatted[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
                Writer.WriteEndElement();
            }
            if (clazz.Tunnus!=null) {
                Writer.WriteStartElement("Tunnus");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Tunnus))).ToString());
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="Vaartus") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Vaartus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Vaartus")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="LyhiVaartus") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.LyhiVaartus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("LyhiVaartus")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="Kirjeldus") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Kirjeldus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Kirjeldus")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="AlgusKP") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.AlgusKP = new global::Xtee.Core.Schema.XsdDateTime(Reader.ReadElementString("AlgusKP")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="LoppKP") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.LoppKP = new global::Xtee.Core.Schema.XsdDateTime(Reader.ReadElementString("LoppKP")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="ObjektID") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>KLVaartus>ObjektID");
                }
                clazz.ObjektID = new global::Xtee.Core.Schema.XsdLong(Reader.ReadElementString("ObjektID")).Value;
            }
            if (Reader.LocalName=="SeaduseSatted") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.SeaduseSatted = new System.Collections.Generic.List<global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.ISeaduseSate>();
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("SeaduseSatted");
                        for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                    && (Reader.LocalName == "item")); ) {
                            if ((Reader.IsElementNil() == false)) {
                                global::Xtee.Core.SerializationMetadata metaSeaduseSatted = this.GetMetaData<global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.ISeaduseSate>(Reader, "SeaduseSate", "http://producers.etoimik.xtee.riik.ee/producer/etoimik");
                                global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.ISeaduseSate item = metaSeaduseSatted.NewEntity<global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.ISeaduseSate>();
                                clazz.SeaduseSatted.Add(item);
                                if ((Reader.IsEmptyElement == false)) {
                                    Reader.ReadStartElement("item");
                                    metaSeaduseSatted.NewSerializer(item).ReadXml(Reader);
                                    Reader.ReadEndElement();
                                }
                                else {
                                    Reader.Skip();
                                }
                            }
                            else {
                                clazz.SeaduseSatted.Add(null);
                                Reader.Skip();
                            }
                        }
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="Tunnus") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Tunnus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Tunnus")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
        }
    }
}
